import CryptoJS from 'crypto-js/crypto-js';

//设置秘钥和秘钥偏移量
const SECRET_KEY = CryptoJS.enc.Utf8.parse("jdty123@56@8jdzy");
// const SECRET_IV = CryptoJS.enc.Utf8.parse("1234567890123456");
/**
 * 加密方法
 * @param word
 * @returns {string}
 */
export const encrypt = (word) => {
  let srcs = CryptoJS.enc.Utf8.parse(word);
  let encrypted = CryptoJS.AES.encrypt(srcs, SECRET_KEY, {
    // iv: SECRET_IV,
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.ZeroPadding,
  });
  return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
};

export const decrypt = word => {
  let base64  = CryptoJS.enc.Base64.parse(word);
  let srcs = CryptoJS.enc.Base64.stringify(base64);
  const decrypt = CryptoJS.AES.decrypt(srcs, SECRET_KEY, {
    // iv: SECRET_IV ,
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.ZeroPadding
  });
  const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  return decryptedStr;
}


export const copy = (arg1={}, arg2={}) => {
  Object.keys(arg1).forEach(key=>{
    arg1[key] = arg2[key]
  })
  return arg1
}

import { useRouter } from "vue-router";
const $router = useRouter();

export const go_web = (src) => {
  if (src.startsWith("http")) {
    window.open(src, "_blank");
  } else {
    $router.push(src);
  }
};

// 获取assets静态资源
export const getAssetsHomeFile = (url: string) => {
  const path = `../assets/images/${url}`;
  const modules = import.meta.globEager("../assets/images/*");
  return modules[path].default;
}